package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "分类查询套餐")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 分类ID查询套餐
     *
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("分类ID查询套餐")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId") // 增加缓存如果存在就直接返回  不存在则增加
    public Result<List<Setmeal>> list(Long categoryId) {
        List<Setmeal> setmeales = setmealService.queryByCategory(categoryId);
        return Result.success(setmeales);
    }

    @GetMapping("/dish/{id}")
    @ApiOperation("套餐ID查询菜品")
    public Result<List<DishItemVO>> queryDish(@PathVariable(value = "id") Long setmealId) {
        List<DishItemVO> dishItemVOS = setmealService.queryDishBySetmealId(setmealId);
        return Result.success(dishItemVOS);
    }
}
